package com.xy.biz.ts.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;

/**
 * @author Greekn Zhang
 * @date 2021/7/14 11:44
 * @description
 */
@Service
public class TrainEventBus {
    private List<Consumer<Long>> afterTrainExaminationList = new CopyOnWriteArrayList<>();

    @Transactional
    public void addTrainExaminationHandler(Consumer<Long> handler) {
        afterTrainExaminationList.add(handler);
    }

    @Transactional
    public void fireTrainExaminationHandler(Long trainId) {
        afterTrainExaminationList.forEach(e -> e.accept(trainId));
    }

}
